package com.security.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.security.domain.SysMenuEntity;
import com.security.domain.SysRoleEntity;
import com.security.domain.SysUserEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/11 14:43
 * @since JDK 1.8
 */
public interface SysUserMapper extends BaseMapper<SysUserEntity> {

    /**
     * 通过用户ID查询角色集合
     * @Author Sans
     * @CreateTime 2019/9/18 18:01
     * @Param  userId 用户ID
     * @Return List<SysRoleEntity> 角色名集合
     */
    @Select("SELECT sr.* FROM sys_role sr LEFT JOIN sys_user_role se ON se.role_id = sr.role_id WHERE se.user_id =#{userId}")
    List<SysRoleEntity> selectSysRoleByUserId(@Param("userId") Long userId);

    /**
     * 通过用户ID查询权限集合
     * @Author Sans
     * @CreateTime 2019/9/18 18:01
     * @Param  userId 用户ID
     * @Return List<SysMenuEntity> 角色名集合
     */
    @Select("SELECT DISTINCT m.* FROM sys_user_role ur LEFT JOIN sys_role_menu rm ON ur.role_id = rm.role_id LEFT JOIN sys_menu m ON rm.menu_id = m.menu_id WHERE ur.user_id = #{userId}")
    List<SysMenuEntity> selectSysMenuByUserId(@Param("userId") Long userId);
}
